package com.dbb.trade.entity.shipment;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Transient;

import com.dbb.trade.entity.IdEntity;
import com.dbb.trade.entity.product.Product;

/**
 * 某一箱规某次出货量
 * @author Administrator
 *
 */
@Entity
public class Groups extends IdEntity {
	
	private Product product;
	private Ctn ctns;
	private Float price = 0f;
	private Integer ctnNum = 0;
	private Groups realGroup = null;
	private Shipment shipment;
	
	public Groups() {
		super();
	}
	
	public Groups(Ctn ctns, Float price, Integer ctnNum) {
		super();
		this.ctns = ctns;
		this.price = price;
		this.ctnNum = ctnNum;
	}
	
	@OneToOne
	@JoinColumn(name = "product_id")
	public Product getProduct() {
		return product;
	}
	public void setProduct(Product product) {
		this.product = product;
	}

	public Float getPrice() {
		return price;
	}

	public Integer getCtnNum() {
		return ctnNum;
	}
	
	public void setCtnNum(Integer ctnNum) {
		this.ctnNum = ctnNum;
	}

	@ManyToOne
	@JoinColumn(name = "ctn_id")
	public Ctn getCtns() {
		return ctns;
	}
	
	public void setCtns(Ctn ctns) {
		this.ctns = ctns;
	}
	
	@Transient
	public Float getTotalPrice(){
		return getTotalPairs() * price;
	}
	@Transient
	public Integer getTotalPairs(){
		return ctns.getPrs() * ctnNum;
	}
	@Transient
	public Float getTotalNw(){
		return ctns.getNetWeight() * ctnNum;
	}
	@Transient
	public Float getTotalGw(){
		return ctns.getGrossWeight() * ctnNum;
	}
	@Transient
	public Float getTotalCbm() {
		return ctns.getCbm() * ctnNum;
	}
	
	@OneToOne
	@JoinColumn(name = "real_group_id")
	public Groups getRealGroup() {
		return realGroup;
	}

	public void setRealGroup(Groups realGroup) {
		this.realGroup = realGroup;
	}
	
	@ManyToOne
	@JoinColumn(name = "SHIPMENT_ID", insertable = false, updatable = false)
	public Shipment getShipment() {
		return shipment;
	}

	public void setShipment(Shipment shipment) {
		this.shipment = shipment;
	}

	@Override
	public String toString() {
		return "Group [ctns=" + ctns + ", price=" + price + ", ctnNum="
				+ ctnNum + ", getPrice()=" + getPrice() + ", getCtnNum()="
				+ getCtnNum() + ", getCtns()=" + getCtns()
				+ ", getTotalPrice()=" + getTotalPrice() + ", getTotalPairs()="
				+ getTotalPairs() + ", getTotalNw()=" + getTotalNw()
				+ ", getTotalGw()=" + getTotalGw() + ", getTotalCbm()="
				+ getTotalCbm() + "]" + (realGroup == null ? "" : ("Real" + realGroup));
	}

	public void setPrice(Float price) {
		this.price = price;
	}
	
}
